public class Solution58 {
    public int lengthOfLastWord(String s) {
        int ans=0;
        int t=s.length()-1;
        while (s.charAt(t)==' ') t--;
        while (t>=0&&s.charAt(t)!=' ') {ans++;t--;}
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution58().lengthOfLastWord("Hello World"));
    }
}
